/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package character_4;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class Character_4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
//        try {
//            int a = System.in.read();//只能读入一个字符编码
//            System.out.println(a);
//        } catch (IOException ex) {
//            Logger.getLogger(Field.class.getName()).log(Level.SEVERE, null, ex);
//        }
        
        Scanner scanner = new Scanner(System.in);//System.in是一种输入流
        int number = (int) (Math.random() * 10);
        int guess;
//        String s = scanner.next();
//        do {
//            System.out.println("猜数字（0-9）：");
//            guess = scanner.nextInt();
//        } while (guess != number);
        
//       System.out.println("猜中了。。。XD");
        
        double a = 0.1, b = 0.1, c = 0.1;
        if((a + b + c) == 0.3){
            System.out.println("等于0.3");
        } else {
            System.out.println("不等于0.3");
        }
        
        BigDecimal operand1 = new BigDecimal("1.0");
        BigDecimal operand2 = new BigDecimal("0.8");
        BigDecimal subtract = operand1.subtract(operand2);
        BigDecimal divide = operand1.divide(operand2);
        System.out.println(subtract);//结果为0.2
        System.out.println(1 - 0.8);//结果为0.19999999999999996
        
        System.out.println(divide);
        System.out.println(1.0 / 0.8);//加乘除不影响
        System.out.println("===================================");
        
        BigDecimal op1 = new BigDecimal("0.1");
        BigDecimal op2 = new BigDecimal("0.1");
        BigDecimal op3 = new BigDecimal("0.1");
        
        BigDecimal result = new BigDecimal("0.3");
        if(op1.add(op2).add(op3).equals(result)) {
            System.out.println("等于0.3");
        } else {
            System.out.println("不等于0.3");
        }
        
        BigDecimal d = new BigDecimal("0.1");
        BigDecimal e = new BigDecimal("0.1");
        BigDecimal f = e;
        System.out.println(d == e);//不是同一对象，所以为false
        System.out.println(d.equals(e));//equals比较对象的值是否相同
        System.out.println(e == f);//绑定为同一对象
        System.out.println(d != e);//结果为true，因为的确没有参考同一对象值
        System.out.println("===================================");
        
        int data1 = 10;
        int data2 = 20;
        
        Integer wrap1 = new Integer(data1);
        Integer wrap2 = new Integer(data2);
        
        System.out.println(data1 / 3);
        System.out.println(wrap1.doubleValue() / 3);//一double类型返回打包的值
        System.out.println(wrap1.compareTo(wrap2));//前面小于后面返回-1，相同为0
        
        Integer i1 = 400;
        Integer i2 = 400;
        if(i1 == i2) {
            System.out.println("i1 == i2");//100的时候相等，200的时候不行，跟IntegeCache.low默认-128，IntegerCache.high默认127有关，在IDE配置IntegerCache.high参数为300后可以显示相等
        } else {
            System.out.println("i1 != i2");
        }
        
        if(i1.equals(i2)) {//使用equals比较式跟值的范围无关，显示相等
            System.out.println("i1 == i2");
        } else {
            System.out.println("i1 != i2");
        }
        System.out.println("===================================");
        
        int[] scores1 = {77, 74, 88, 95, 59};//建议这种方式
        int scores2[] = {77, 74, 88, 95, 59};
        for(int score : scores1){//增强式for循环
            System.out.println("分数"+score);
        }
        
        int[][] cords = {
            {1,2,3},
            {4,5,6}
        };
        System.out.println("haha"+cords.length);
        for (int[] cord : cords) {//增强式for循环遍历二维数组
            for (int i : cord) {
                System.out.printf("%4d",i);
            }
            System.out.println("");
        }
        int[] scores = new int[10];//该种方式会赋初值0
        for (int score : scores) {
            System.out.printf("%4d", score);
        }
        System.out.println("");
        Arrays.fill(scores, 60);//设初值
        for (int score : scores) {
            System.out.printf("%4d", score);
        }
        int[][] arr = new int[2][];
        arr[0] = new int[]{1,2,3};//必须这么写
        
        Integer[] scor = new Integer[3];//每个索引参考至null
        scor[0] = new Integer(99);
        System.out.println(scor[0]);
        Integer[] score1 = {new Integer(11), new Integer(22)};
        
        int[] s1 = {1,2,3};
        int[] s2 = new int[s1.length];
        System.arraycopy(s1, 0, s2, 0, s1.length);//来源数组，来源起始索引，目的数组，目的起始索引，复制长度
        for (int i : s2) {
            System.out.println(i);
        }
        int[] s3 = Arrays.copyOf(s1, s1.length * 2);//方便,自动建数组，后面10个值默认0
        for (int i : s3) {
            System.out.println(i);
        }
        
        Clothes[] c1 = {new Clothes("blue", 'S'), new Clothes("red", 'L')};
        Clothes[] c2 = new Clothes[c1.length];
        for (int i = 0; i < c2.length; i++) {
            c2[i] = c1[i];
        }
        c1[0].color = "yellow"; 
        System.out.println(c2[0].color);//浅层复制，只是复制参考，没有将对象复制过去，System.arraycopy和Arrays.copyOf()也不可以，只能自行复制，内部元素单独复制
        System.out.println("===================================");
        
        String name = "LiMing";
        System.out.println(name);
        System.out.println(name.length());
        System.out.println(name.charAt(0));
        System.out.println(name.toUpperCase());//转为大写
        char[] cs = {'L','i','M','i','n','g'};
        String na = new String(cs);
        System.out.println(na);
        char[] cs2 = name.toCharArray();//字符串转服字符数组
        for (char g : cs2) {
            System.out.println(g);
        }
        long sum = 0;
        long num = 0;
//        do {            
//            System.out.println("请输入数字：");
//            num = Long.parseLong(scanner.nextLine());
//            sum += num;
//        } while (num != 0);
        System.out.println("总和" + sum);
        String name1 = new String(name);
        String name2 = new String(name);
        System.out.println(name1 == name2);
        
        String name3 = "LiMing";
        String name4 = "LiMing";
        System.out.println(name3 == name4);//常量字符串内容相同，只建立一个String实例
        System.out.println(name1.equals(name2));//比较实质内容用equals
        
        for (int i = 0; i <= 100; i++) {
            System.out.printf("%d+",i);
        }
        String text = "";
        for (int i = 0; i <= 100; i++) {
            text = text + i + "+";
        }
        System.out.println(text);
        
        String t1 = "Ja" + "va";//都是常量，编译时直接看为"Java"
        String t2 = "Java";
        System.out.println(t1 == t2);
        System.out.println("哈哈");
        
        int x = 100;
        int y = 100;
        Integer x1 = x;
        Integer y1 = y;
        System.out.println(x1.equals(x));
        System.out.println(y1.equals(y));
        
        int[] arr1 = {1,2,3};
        int[] arr2 = arr1;//指向同一数组，要想复制需另建新数组
        arr2[1] = 20;
        System.out.println(arr1[1]);
        
        int[] arr3 = new int[arr1.length];
        arr3 = arr1;
        for (int i : arr3) {
            System.out.printf("%d%n",i);
        }
        System.out.println("===================================");
        //System.out.println(fib(5));
        
        long f1,f2;
        int i;
        f1=1;
        f2=1;
        for(i=1;i<=5;i++) {
            System.out.printf("%6d %6d",f1,f2);
            if(i%2==0)
            System.out.printf("\n");
            f1=f1+f2;
            f2=f2+f1;
        }
        
        char[] puke = {'3', '4', '5', '7','8', '9', 'J', 'Q', 'K', 'A', '2', 'W'};
        Random rd = new Random();
        
        for (int j = 0; j < 11; j++) {
            int aa = rd.nextInt(11);
            char temp = puke[aa];
            puke[aa] = puke[i];
            puke[i] = temp;
        }
        for (char g : puke) {
             System.out.println(g);
        }
        
    }
    
    
       public static int fib(int n){
        if (n == 1 || n == 2) {
            System.out.println(1);
            return 1;
        }
        System.out.println(n);
        return fib(n-1) + fib(n-2);
    }
}
